# coding=utf8
from appium import webdriver
import time,traceback

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.1.0'
desired_caps['deviceName'] = 'test'
# desired_caps['app'] = r'F:\apk\toutiao.apk'
desired_caps['appPackage'] = 'io.manong.developerdaily'
desired_caps['appActivity'] = 'io.toutiao.android.ui.activity.LaunchActivity'
desired_caps['unicodeKeyboard']  = True
desired_caps['resetKeyboard']  = True
desired_caps['noReset'] = True
desired_caps['newCommandTimeout'] = 6000
#启动Remote RPC
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# #选择发现
# code='new UiSelector().text("发现").className("android.widget.TextView")'
# driver.find_element_by_android_uiautomator(code).click()

#选择我的
codes='new UiSelector().resourceId("io.manong.developerdaily:id/tab_bar").childSelector(new UiSelector().className("android.widget.TextView").instance(3))'

driver.find_element_by_android_uiautomator(codes)
# try:
# #     driver.implicitly_wait(10)
# #
#     # 根据id找到元素，并点击，id和 html 元素的id不同
#
#     driver.find_element_by_id("io.manong.developerdaily:id/tab_bar_plus").click()
#     time.sleep(1)
#
#     driver.find_elements_by_class_name("android.widget.RelativeLayout")[1].click()
#     time.sleep(1)
#
#     # 输入用户名、密码
#     ele = driver.find_element_by_id("io.manong.developerdaily:id/edt_phone")
#     ele.send_keys('15218701897')
#
#     ele = driver.find_element_by_id("io.manong.developerdaily:id/edt_password")
#     ele.send_keys('910501')
#
#     time.sleep(2)
#     # 点击登录
#     driver.find_element_by_id('io.manong.developerdaily:id/btn_login').click()
#     pass
#
# except:
#     print (traceback.format_exc())
#
#
# input('**** Press to quit..')
# driver.quit()

